package com.ansion.utils;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;

public class CommonUtil {
    public static <T> boolean isEmpty(Collection<T> c) {

        return c == null || c.isEmpty();
    }

    public static boolean isEmpty(String s) {

        return s == null || s.equals("");
    }

    public static <K, V> boolean isEmpty(Map<K, V> mp) {

        return mp == null || mp.isEmpty();
    }

    public static int compareLong(long l1, long l2) {
        return l1 < l2 ? -1 : l1 == l2 ? 0 : 1;
    }

    public static boolean isEqual(List<String> c1, List<String> c2) {
        if (c1 == null || c2 == null)
            return false;
        if (c1.isEmpty() || c2.isEmpty())
            return false;
        List<String> c1Copy = new ArrayList<>(c1);
        List<String> c2Copy = new ArrayList<>(c2);
        Collections.sort(c1Copy, new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                return Integer.compare(o1.hashCode(), o2.hashCode());
            }
        });
        Collections.sort(c2Copy, new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                return Integer.compare(o1.hashCode(), o2.hashCode());
            }
        });
        return c1Copy.toString().equals(c2Copy.toString());
    }


}
